@extends('layouts.admin')
@section('css')
    <link rel="stylesheet" href="{{asset('vendors/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css')}}">
    <style>
        .info-list {
            margin-left: 20px;
            line-height: 30px;
        }
        .info-list-inner {
            padding-left: 20px;
        }
        .info-list-inner > label {
            font-weight: normal;
        }
        .group-wrap {
            margin: 14px 0;
        }
    </style>
@endsection @section('content')
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>{!!trans('admin/apply.title')!!}</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{{url('admin/dash')}}">{!!trans('admin/breadcrumb.home')!!}</a>
                </li>
                <li>
                    <a href="{{url('admin/apply')}}">{!!trans('admin/apply.title')!!}</a>
                </li>
                <li class="active">
                    <strong>{!!trans('admin/apply.show.title')!!}</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                @include('flash::message')
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{!!trans('admin/apply.baseinfo')!!}</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="">
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.id')}}：</label>
                                <span>{{$apply->id}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.status')}}：</label>
                                <span class="apply-status">{{$apply->status}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.stage')}}：</label>
                                <span class="apply-stage">{{$apply->stage}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.apply')}}：</label>
                                <span class="apply-apply">{{$apply->apply}}</span>
                            </div>
                        </div>
                    </div>
                    <!-- <div class="hr-line-dashed"></div> -->
                    <div class="ibox-content">
                        <div>
                            <div class="info-list">
                                <span><img src="{{$apply->photo}}/250" alt=""></span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.name')}}：</label>
                                <span>{{$apply->name}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.sex')}}：</label>
                                <span class="apply-sex">{{$apply->sex}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.degree')}}：</label>
                                <span class="apply-degree">{{$apply->degree}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.phone')}}：</label>
                                <span>{{$apply->phone}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.wechat')}}：</label>
                                <span>{{$apply->wechat}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.qq')}}：</label>
                                <span>{{$apply->qq}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.email')}}：</label>
                                <span>{{$apply->email}}</span>
                            </div>
                        </div>
                    </div>
                    <!-- <div class="hr-line-dashed"></div> -->
                    <div class="ibox-content">
                        <div>    
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.province')}}：</label>
                                <span class="apply-province">{{$apply->province}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.city')}}：</label>
                                <span>{{$apply->city}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.school')}}：</label>
                                <span>{{$apply->school}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.zone')}}：</label>
                                <span>{{$apply->zone}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.profession')}}：</label>
                                <span>{{$apply->profession}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.education')}}：</label>
                                <span class="apply-education">{{$apply->education}}</span>
                            </div>
                            <div class="info-list">
                                <label for="">{{trans('admin/apply.show.grade')}}：</label>
                                <span class="apply-grade">{{$apply->grade}}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{!!trans('admin/apply.moreinfo')!!}</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="apply-applyDetail" data-json="{{$apply->applyDetail}}">
                            <div class="info-list">
                                <label for=""></label>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="group-wrap apply-ogranization" data-json="{{$apply->organization}}">
                            <div class="info-list">
                                <label for="">参加的学生会/社团等校内组织：</label>
                                <span class="" id="org"></span>
                            </div>
                        </div>
                        <div class="group-wrap apply-innerActivity">
                            <div class="info-list">
                                <label for="">参加了的校内活动：</label>
                                <span class="">{{$apply->innerActivity}}</span>
                            </div>
                        </div>
                        <div class="group-wrap apply-meizuOrg" data-json="{{$apply->meizuOrg}}">
                            <div class="info-list">
                                <label for="">参加的魅族其他组织：</label>
                                <span class="" id="meizuOrg"></span>
                            </div>
                        </div>
                        <div class="group-wrap apply-outerOrg" data-json="{{$apply->outerOrg}}">
                            <div class="info-list">
                                <label for="">参加的其他校外组织：</label>
                                <span class="" id="outerOrg"></span>
                            </div>
                        </div>
                        <div class="group-wrap apply-outerActivity">
                            <div class="info-list">
                                <label for="">参加了的校外活动：</label>
                                <span class="">{{$apply->outerActivity}}</span>
                            </div>
                        </div>
                    </div>
                </div>

                {{--审核模块--}}
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>审核</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="old-review-data">
                            @foreach( $reviews as $review)
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <span class="apply-stage">{{$review->stage}}</span> ·
                                        <span class="apply-status">{{$review->status}}</span> ·
                                        <span class="apply-admin">{{$review->admin->name}}</span>
                                    </div>
                                    <div class="panel-body">
                                        <p><i class="fa fa-comment"></i> 审核：{{$review->evaluation}}</p>
                                        <p><i class="fa fa-pencil"></i> 备注：{{$review->remark}}</p>
                                    </div>
                                </div>
                            @endforeach
                        </div>

                        @if($apply->canReview)
                            <div class="hr-line-dashed"></div>
                            <div class="review">
                                <form method="post" action="{{url('admin/apply/review')}}" class="form-horizontal">
                                    {{csrf_field()}}
                                    <input type="hidden" name="id" value="{{$apply->id}}">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">审核</label>
                                        <div class="col-sm-11">
                                            <textarea class="form-control" name="evaluation"
                                                      rows="5">{{old('evaluation')}}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">备注</label>
                                        <div class="col-sm-11">
                                            <textarea class="form-control" name="remark"
                                                      rows="5">{{old('remark')}}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">结果</label>
                                        <div class="col-sm-11">
                                            <label class="radio-inline">
                                                <input type="radio" name="status" id="inlineRadio1" value="1"> 待定
                                            </label>
                                            <label class="radio-inline">
                                                <input type="radio" name="status" id="inlineRadio2" value="2"> 通过
                                            </label>
                                            <label class="radio-inline">
                                                <input type="radio" name="status" id="inlineRadio3" value="3"> 拒绝
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-1">
                                            <button class="btn btn-primary"
                                                    type="submit">{!!trans('admin/action.actionButton.submit')!!}</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>


@endsection
@section('js')
    <script src="{{asset('vendors/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js')}}"></script>
    <script src="{{asset('admin/js/bootstrap3-typeahead.min.js')}}"></script>
    <script src="{{asset('admin/js/apply/transform.js')}}"></script>
    <script>
        $(function () {
            var $applyApply = $('.apply-apply');
            console.log($applyApply.text());
            $applyApply.each(function (i, item) {
                item = $(item);
                item.html(transformApply(item.text()));
            });

            var $applyStatus = $('.apply-status');
            $applyStatus.each(function (i, item) {
                item = $(item);
                item.html(transformStatus(item.text()));
            });

            var $applyStage = $('.apply-stage');
            $applyStage.each(function (i, item) {
                item = $(item);
                item.html(transformStage(item.text()));
            });

            var $applySex = $('.apply-sex');
            $applySex.each(function (i, item) {
                item = $(item);
                item.html(transformSex(item.text()));
            });

            var $applySex = $('.apply-degree');
            $applySex.each(function (i, item) {
                item = $(item);
                item.html(transformDegree(item.text()));
            });

            $('.apply-province').each(function (i, item) {
                item = $(item);
                item.html(transformProvince(item.text()));
            });

            var $applyEducation = $('.apply-education');
            $applyEducation.each(function (i, item) {
                item = $(item);
                item.html(transformEducation(item.text()));
            });

            var $applyGrade = $('.apply-grade');
            $applyGrade.each(function (i, item) {
                item = $(item);
                item.html(transformGrade(item.text()));
            });

            //解析applyDetail
            var $applyDetail = $('.apply-applyDetail');
            var dataJson = $applyDetail.attr('data-json');
            dataJson = JSON.parse(dataJson);
            console.log(dataJson);
            $.each(dataJson, function (key, item) {
                if ((typeof item === 'object') && (key !== 'scoreUpSkill') && (key !== 'fileLink') && (key !== 'uploadFileName')) {
                    $.each(item, function (i, obj) {
                        $.each(obj, function (k, v) {
                            v = transformNum123(k, v);
                            $applyDetail.append(
                              `<div class="info-list info-list-inner">
                                <label class="need-transform-label" for="">${k}</label>
                                <span>${v}</span>
                              </div>`
                            );
                        });
                    });
                } else if (key === 'scoreUpSkill') {
                    item = item.join('、');
                    $applyDetail.append(
                        `<div class="info-list">
                            <label class="need-transform-label" for="">${key}</label>
                            <span>${item}</span>
                        </div>`
                    );
                } else if (key === 'fileLink') {
                    item = item.join('、');
                    $applyDetail.append(
                        `<div class="info-list">
                            <label class="need-transform-label" for="">${key}</label>
                            <span>${item}</span>
                        </div>`
                    );
                } else if (key === 'uploadFileName') {
                    // do nothing
                } else {
                    item = transformNum12(key, item);
                    $applyDetail.append(
                        `<div class="info-list">
                            <label class="need-transform-label" for="">${key}</label>
                            <span>${item}</span>
                        </div>`
                    );
                }
            });

            // 解析organization
            var $applyOrganization = $('.apply-ogranization');
            var dataOrg = $applyOrganization.attr('data-json');
            dataOrg = JSON.parse(dataOrg);
            if (dataOrg.length === 0) {
                    $('#org').text('无');
                } else {
                    $.each(dataOrg, function(key, item) {
                        $.each(item, function(k, i) {
                            $applyOrganization.append(
                                `<div class="info-list info-list-inner">
                                    <label class="need-transform-label" for="">${k}</label>
                                    <span>${i}</span>
                                </div>`
                            )
                        })
                    });
                }
            

            // 解析MeizuOrg
            var $applyMeizuOrg = $('.apply-meizuOrg');
            var dataMeizuOrg = $applyMeizuOrg.attr('data-json');
            dataMeizuOrg = JSON.parse(dataMeizuOrg);
            console.log(dataMeizuOrg);
            if (dataMeizuOrg.length === 0) {
                    $('#meizuOrg').text('无');
                } else {
                    $.each(dataMeizuOrg, function(key, item) {
                        $.each(item, function(k, i) {
                            $applyMeizuOrg.append(
                                `<div class="info-list info-list-inner">
                                    <label class="need-transform-label" for="">${k}</label>
                                    <span>${i}</span>
                                </div>`
                            )
                        })
                    });
                }
           

            // // 解析outerOrg
            var $applyOuterOrg = $('.apply-outerOrg');
            var dataOuterOrg = $applyOuterOrg.attr('data-json');
            dataOuterOrg = JSON.parse(dataOuterOrg);
            if (dataOuterOrg.length === 0) {
                    $('#outerOrg').text('无');
                } else {
                    $.each(dataOuterOrg, function(key, item) {
                        $.each(item, function(k, i) {
                            $applyOuterOrg.append(
                                `<div class="info-list info-list-inner">
                                    <label class="need-transform-label" for="">${k}</label>
                                    <span>${i}</span>
                                </div>`
                            )
                        })
                    });
                }
            
            $('.need-transform-label').each(function (i, item) {
                item = $(item);
                if (transformLabel(item.text(), $applyApply.text()) === undefined) {
                    item.parent().css('display', 'none');
                } else {
                    item.html(transformLabel(item.text(), $applyApply.text()) + '：');
                }
            });
        })
    </script>
@endsection